<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('通过并再回T')"/>
    <style>
        label {
            font-weight: bold;
        }

        @font-face {
            font-family: 'huawen';
            src: url("/fonts/huawen.woff2");
        }
    </style>
</head>

<body style="background-color: #F4F6FA;font-size: 13px;font-family:'huawen' ;font-weight: bold">
<div class="main-content" style="margin: 0;padding: 0">
    <form id="form-user-add" th:object="${sendBackEty}" class="form-horizontal" style="background-color: #F4F6FA">
        <input type="hidden" id="pkId" name="pkId" th:value="*{pkId}"/>
        <input type="hidden" id="sortCode" name="sortCode" th:value="*{sortCode}"/>
        <input type="hidden" id="sdeptName" name="sdeptName" th:value="*{sdeptName}"/>
        <input type="hidden" id="sdeptId" name="sdeptId" th:value="*{sdeptId}"/>
        <input type="hidden" id="sbdeptName" name="sbdeptName" th:value="*{sbdeptName}"/>
        <input type="hidden" id="sdeptId" name="sbdeptId" th:value="*{sbdeptId}"/>
        <input type="hidden" name="backState" id="backState" th:value="*{backState}"/>
        <input type="hidden" id="wfId" name="wfId" th:value="${wfId}"/>
        <input type="hidden" id="sendId" name="sendId" th:value="${sendId}"/>
        <input type="hidden" id="crtUserRole" th:value="${user.roles.get(0).roleId}"/>
        <input type="hidden" name="crtStepId" id="crtStepId"/>
        <input type="hidden" name="crtStepName" id="crtStepName"/>
        <input type="hidden" name="opinion" id="opinion">
        <input type="hidden" name="txtReason" id="txtReason">

        <div class="col-sm-12 grid-container" style="display:flex;">
            <div class="col-sm-6 entering-page">
                <!--    回复电话工单    -->
                <div class="col-sm-12 tltieBoder">
                    <div class="blueBorder"></div>
                    <h4 style="margin:0 0 0 10px">回复信息</h4>
                </div>
                <!--    隐藏内容       -->
                <div style="display: none">
                    <div class="col-sm-12">
                        <div class="form-group">
                            <label class="col-sm-3 control-label entering-pd">建议办结及理由：</label>
                            <div class="col-sm-6">
                                <textarea th:field="*{reason}" maxlength="1000"
                                          class="form-control"
                                          cols="60"
                                          rows="3"></textarea>
                            </div>
                        </div>

                    </div>
                    <div class="col-sm-12">
                        <div class="form-group">
                            <label class="col-sm-3 control-label entering-pd" style="color: red">执行处(科)室：</label>
                            <div class="col-sm-6">
                                <input th:field="*{bdutyDept}" type="text" class="form-control">
                            </div>
                        </div>
                    </div>
                    <div class="col-sm-12">
                        <div class="form-group">
                            <label class="col-sm-3 control-label entering-pd" style="color: red">联系电话：</label>
                            <div class="col-sm-6">
                                <input th:field="*{bdutyTel}" type="text" class="form-control">
                            </div>
                        </div>
                    </div>
                    <div class="col-sm-12">
                        <div class="form-group">
                            <label class="col-sm-3 control-label entering-pd">回复人：</label>
                            <div class="col-sm-6">
                                <input name="buserName" th:value="${user.userName}" type="text" class="form-control">
                                <input type="hidden" name="buserNo" th:value="${user.userNo}"/>
                            </div>
                        </div>
                    </div>
                    <div class="col-sm-12">
                        <div class="form-group">
                            <label class="col-sm-3 control-label entering-pd">回复时间：</label>
                            <div class="col-sm-6">
                                <input name="backTime" th:value="${nowTime}" type="text" class="form-control">
                            </div>
                        </div>
                    </div>
                    <div class="col-sm-12">
                        <div class="form-group">
                            <label class="col-sm-3 control-label entering-pd">备注：</label>
                            <div class="col-sm-6">
                                <input th:field="*{backRemark}" type="text" class="form-control">
                            </div>
                        </div>
                    </div>
                </div>
                <div class="col-sm-12">
                    <div class="form-group">
                        <label class="col-sm-2 control-label entering-pd" style="color: red">回复内容:</br>(供派单部门使用)</label>
                        <div class="col-sm-10">
                            <select name="replyRc" id="replyRc"
                                    th:with="replyRn=${replyTemplate}"
                                    onchange="dropChgSendTextOnly(this,'backDesc');"
                                    class="form-control m-b phoneCategory">
                                <th:block th:each="item,index : ${replyRn}">
                                    <option th:text="${item['replyRn']}" th:value="${item['replyNo']}"></option>
                                </th:block>
                            </select>
                            <textarea id="backDesc" th:field="*{backDesc}" maxlength="3500"
                                      class="form-control opinion"
                                      rows="7" required="required"></textarea>
                        </div>
                    </div>
                </div>
                <!--按钮-->
                <div class="col-sm-12" style="display: flex;justify-content:center;margin:15px 0px 15px 0px">
                    <div class="form-group">
                        <div class="col-sm-3 col-sm-offset-6"  style="display: flex;justify-content: space-evenly;">
                            <button type="button" class="btn btn-sm btn-success" th:if="*{backState==0 && backDesc==null}" onclick="sub()">回复</button>&nbsp;&nbsp;&nbsp;&nbsp;
                            <button type="button" class="btn btn-sm btn-primary" th:unless="*{backState==0 && backDesc==null}" onclick="alterReply()">修改回复</button>&nbsp;&nbsp;&nbsp;&nbsp;
                        </div>
                    </div>
                </div>
            </div>
            <div class="col-sm-6" style="padding: 0;margin-top: 10px;">
                <th:block th:each="sons,stat: ${sonBackList}">
                    <div class="col-sm-6 pd2" th:if="${son != null}" th:unless="${#lists.isEmpty(sonBackList)}"  th:each="son,stat: ${sons}">
                        <div class="ibox mbi10">
                            <div class="ibox-title">[[${son.sbdeptName}]]&nbsp;回复审核情况：
                                <span th:switch="${son.backState}">
                                    <span th:case="0" style="color: red">未回复</span>
                                    <span th:case="10" style="color: #6cc315">已回(未审)</span>
                                    <span th:case="*" style="color: #2752d5">已审</span>
                                </span>
                            </div>
                            <div class="ibox-content">
                                <p>交办次序：[[${son.seqName}]] <a th:unless="${#strings.isEmpty(son.backDesc)}" style="float: right;" class="btn btn-outline btn-primary copyBtn" onclick="copyBackDesc(this);return false;">复制</a></p>
                                <p>办理性质：[[${son.sortName}]]</p>
                                <p>执行处(科)室：[[${son.bdutyDept}]]</p>
                                <p>回复人：[[${son.buserName}]]</p>
                                <p>联系电话：[[${son.bdutyTel}]]</p>
                                <p>回复时间：[[${#dates.format(son.backTime,'yyyy-MM-dd HH:mm:ss')}]]</p>
                                <p><span>回复内容：<span><span class="replyContent">[[${son.backDesc}]]</span></p>
                            </div>
                        </div>
                    </div>
                </th:block>
            </div>
        </div>
    </form>
</div>

<th:block th:include="include :: footer"/>
<script>
    var prefix = ctx + "system/mTelWF";

    // 获取用户部门，展示是否显示回复并审核按钮
    var nowDept = [[${session.ssnObjUser.deptId}]];


    function sub() {
        //根据当前登录用户的角色决定由哪个部门审查
        var stepRoles = "210,240,260,290,310,340";
        var crtRole = $("#crtUserRole").val();
        if (stepRoles.indexOf(crtRole) > -1) {
            $("#crtStepId").val("800");
            $("#crtStepName").val("待市级部门审查");
        } else { //三级不驱动流程
            $("#crtStepId").val("400");
            $("#crtStepName").val("待区县部门审查");
        }
        if ($.validate.form()) {
            var backDesc = "reply"+$("#backDesc").val();
            $("#backDesc").val(backDesc);
            let url = prefix + "/cmnFile/dlReplyS";
            let data = $('#form-user-add').serializeArray();
            $.operate.saveTab(url, data, callback);
        }
    }

    function callback(res){
        if(res.code === 0){
            $("#pkId").val($("#sendId").val());//审核下级
            passOrNot(1)
            $.modal.msgSuccess("回复成功！")
            $.modal.close();
            $.modal.closeTab();
        }
    }

    //修改回复
    function alterReply(){
        var backDesc = "reply"+$("#backDesc").val();
        $("#backDesc").val(backDesc);
        var data = $('#form-user-add').serializeArray();
        $.ajax({
            url: "/system/mTelWF/btnReplyClick",
            type: "POST",
            dataType: 'json',
            data: data,
            success: function(result) {
                $("#pkId").val($("#sendId").val());
                passOrNot(1)
                $.modal.alertSuccess("修改成功！");
                $.modal.close();
                $.modal.closeTab();
            },
            error: function (){
                $.modal.alertSuccess("修改失败！");
                $.modal.close();
                $.modal.closeTab();
            }
        })
    }

    function dropChgSendTextOnly(e,acpId) {
        if (e.options[e.selectedIndex].text==='----请选择回复内容----') return '';
        let showText = $("#replyRc").find("option:selected").text();
        document.getElementById(acpId).value = showText + '\n';
    }

    function passOrNot(flag) {
        var act = parseInt(flag);
        if (act < 1) {
            if ($("#txtReason").val().length < 1) {
                $.modal.alertWarning("请输入不通过理由");
                return false;
            }
            $("#opinion").val("不同意");
            $("#backState").val("22");
        } else {
            if ($("#opinion").val().length < 1) {
                $("#opinion").val("同意");
                $("#backState").val("21");
            }
            $("#opinion").val("同意");
            $("#backState").val("21");
        }
        if ($.validate.form()) {
            let url = prefix + "/rCity/sendBackChkJson";
            let data = $('#form-user-add').serializeArray();
            $.operate.saveTab(url, data, refreshTListSonOver);
        }
    }

    // 刷新下级已办毕-待处理列表
    function refreshTListSonOver() {
        var navFrame = $('.NAP_iframe[data-id="/system/cmnTab/tListSonOverTab"]', parent.document).contents().find('#navFrame')[0];
        navFrame.contentWindow.$.table.refresh();
    }
</script>
</body>
</html>

